package com.xxh.blog.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xxh.blog.entity.vo.EssayVo;
import com.xxh.blog.service.SearchService;
import com.xxh.blog.service.essayService;
import com.xxh.blog.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class testController {

    @Autowired
    essayService essayService;

    @Autowired
    SearchService searchService;

    /**
     * 同步数据库数据
     * @return
     */
    @ResponseBody
    @RequestMapping("/init/test")
    public Result initEsDate(){

        int size=100;
        Page page = new Page();
        page.setSize(size);

        for(int i=0;i<10;i++){
            page.setCurrent(i);
            IPage<EssayVo> paging = essayService.paging(page, null, null, null, null, null);
            searchService.initEsDate(paging.getRecords());
            //说明数据同步完成
            if(paging.getRecords().size()<size){
                break;
            }
        }
        return Result.ok("同步完成");
    }
}
